package org.usmile.algorithms.huawei.acm;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

// https://blog.csdn.net/qq_34465338/article/details/128372540
public class _基站维修工程师 {
    private static int[][] metric;
    private static boolean[] visited;
    private static int n;
    private static int min = Integer.MAX_VALUE;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        sc.nextLine();
        metric = new int[n][n];
        visited = new boolean[n];
        for (int row = 0; row < n; row++) {
            for (int col = 0; col < n; col++) {
                metric[row][col] = sc.nextInt();
            }
        }
        List<Integer> path = new ArrayList<>();
        for (int start = 1; start < n; start++) {
            path.add(start);
            visited[start] = true;
            dfs(start, path, metric[0][start]);
            visited[start] = false;
            path.remove(path.size() - 1);
        }
        System.out.println(min);
    }

    private static void dfs(int prev, List<Integer> path, int currValue) {
        if (path.size() == n - 1) {
            min = Math.min(min, currValue + metric[prev][0]);
        }
        for (int next = 1; next < n; next++) {
            if (!visited[next]) {
                path.add(next);
                visited[next] = true;
                dfs(next, path, currValue + metric[prev][next]);
                path.remove(path.size() - 1);
                visited[next] = false;
            }
        }
    }
}
